package cn.lxh.basic.service.impl;

import cn.lxh.basic.mapper.BaseMapper;
import cn.lxh.basic.query.BaseQuery;
import cn.lxh.basic.service.IBaseServiece;
import cn.lxh.basic.utils.PageList;
import cn.lxh.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServieceImpl<T> implements IBaseServiece<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public List<T> queryAll() {
        return mapper.findAll();
    }

    @Override
    public T queryById(Long id) {
        return (T)mapper.findById(id);
    }
    @Transactional
    @Override
    public void save(T t) {
        mapper.save(t);
    }
    @Transactional
    @Override
    public void update(T t) {
        mapper.update(t);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public PageList queryList(BaseQuery tQuery) {
        Integer total = mapper.queryCount(tQuery);
        List<T> rows = mapper.queryData(tQuery);
        return new PageList(total,rows);
    }
    @Transactional
    @Override
    public void batchReove(Long[] ids) {
        mapper.batchRemove(ids);
    }
}
